package com.cyd.demo3.controller;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description : 描述
 * Created by cyd on 2021-05-13 12:01:37
 */
@WebServlet(name = "fourServlet", value = "/four")
public class FourServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");

        ServletContext servletContext = req.getServletContext();
        servletContext.setAttribute("outPutByFour", new String("<h2>four: 麻醉</h2>"));

        System.out.println("four: 麻醉");
//        PrintWriter out = resp.getWriter();
//        out.print("<h2>four: 麻醉</h2>");
        // 参数只能放动态资源的别名
        RequestDispatcher dispatcher = req.getRequestDispatcher("/five");
        dispatcher.forward(req, resp);
    }
}
